package com.itheima.controller;

import com.itheima.domain.Movie;
import com.itheima.service.MovieService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 影视管理接口
 * @Author: hsp
 * @Date: 2022/11/16-11-16-23:59
 * @Description: com.itheima.controller
 * @version: 1.0.0
 */
//自动将返回的数据转换成json字符串  @RestController=@Controller + @ReponseBody
@RestController
@RequestMapping("/admin/movie")
public class MovieController {

    @Resource
    private MovieService movieService;

    //@GetMapping = @RequestMapping(value = "/users" ,method = RequestMethod.GET)+@ReponseBody
    //查询所有影视列表
    @GetMapping(value = "/findAll")
    public List<Movie> findAll (){
        return movieService.findAll();
    }

    //@RequestBody ?
    @PostMapping("/save")
    public void save(@RequestBody Movie movie){
        if (movie.getId() == null){
            //新增影视
            movieService.save(movie);
        }else {
            //根据id修改影视
            movieService.update(movie);
        }
    }

    //根据影视id查询影视详情
    @GetMapping("/findById")
    public Movie findById (Integer id) {
        return movieService.findById(id);
    }

    //根据影视id删除影视
    @DeleteMapping("/deleteById")
    public void deleteById (Integer id){
        movieService.deleteById(id);
    }

    //批量删除影视
    @DeleteMapping("/deleteByIds")
    public void deleteByIds (Integer[] ids){
        movieService.deleteByIds(ids);
    }



}
